<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<mesoBoard.Data.Config>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <% if(false){ %>
        <script language="javascript" type="text/javascript" src="../Scripts/jquery-1.3.2.min-vsdoc.js">
    	</script>
    <%} %>
    <script type="text/javascript" language="javascript">
        $(function () {
            $("#tabs").tabs();
        });
    </script>

    <% if (TempData["Errors"] != null) {
           ICollection<string> msd = (ICollection<string>)TempData["Errors"];
           if (msd.Count != 0) { %>
               <p>Missing Fields:</p>
               <ul class="validation-summary-errors">
           <% } 
           foreach (string e in msd) { %>
           <li><%= e %></li>
           <% } if (msd.Count != 0) { %>
           </ul>
            <% }
       } %>

    <div id="tabs">
        <% using(Html.BeginForm()){ %>

        <fieldset>
            <legend><%= Html.ThemeImage("hammer_screwdriver.png")%> Configuration</legend>
            <ul>
                <% foreach(string s in (string[])ViewData["Settings"]){ %>
                    <li><a href="#<%= s.Replace(" ", "") %>"><%= s %></a></li>
                <%} %>
            </ul>
        </fieldset>

            <% foreach(string s in (string[])ViewData["Settings"]){ %>
            <div id="<%= s.Replace(" ", "") %>">
                <fieldset>
                    <legend><%= s %></legend>
                    <dl class="details">
                        <% foreach(Config c in Model.Where(x=>x.Group == s.Replace(" ", ""))){ %>
                            <dt><%= c.Name %></dt>
                            <dd>
                               <% if (c.Name == "BoardTheme") {%>
                                     <%= Html.DropDownList("BoardTheme")%>
                               <% } else {
                                     switch (c.Type)
                                     {
                                         case "bool[]":
                                             string[] vals = c.Value.Split(',');
                                             string[] splits = c.Options.Split(',');
                                             foreach (string bo in splits) { %>
                                                <input type="checkbox" name="<%= c.Name %>" id="<%= bo %>" value="<%= bo %>" <%= vals.Contains(bo) ? "checked" : ""  %> />
                                                <%= Html.Label(bo, bo, "inline")%>
                                             <% }
                                             break;
                                             
                                         case "string[]":
                                             string[] splitOptions = c.Options.Split(',');
                                             SelectList d = new SelectList(splitOptions.AsEnumerable(), c.Value); %>
                                             <%= Html.DropDownList(c.Name, d.AsEnumerable())%>
                                             <% break;
                                             
                                         case "string":%>
                                            <%= Html.TextBox(c.Name, c.Value, new { @class = "string" })%>
                                            <% break;

                                         case "int":%>
                                            <%= Html.TextBox(c.Name, c.Value, new { @class = "int" })%>
                                            <% break;

                                         case "bool":%>
                                            <%= Html.RadioButton(c.Name, "true", c.Value.Equals("true", StringComparison.InvariantCultureIgnoreCase), new { id = c.ConfigID + "true" })%> 
                                            <%= Html.Label(c.ConfigID + "true", "True", "inline") %>
                                        
                                            <%= Html.RadioButton(c.Name, "false", c.Value.Equals("false", StringComparison.InvariantCultureIgnoreCase), new { id = c.ConfigID + "false" })%> 
                                            <%= Html.Label(c.ConfigID + "false", "False", "inline")%>
                                            <% break;
                                     }
                                 }%>
                                 <label style="display: block"><%= c.Note%></label>
                            </dd>
                        <% } %>
                    </dl>
                </fieldset>
            </div>
           <% } %>

                   
        <p style="text-align: center; background-color: #eef2f9; border: solid 1px #ccc; padding: 5px;">
            <%= Html.SubmitButton("SaveChanges", "Save Changes") %>
        </p>
    <% } %>
    </div> 

</asp:Content>
